﻿using System;
using JetBrains.Annotations;

namespace Rsdn.SmartApp.Old
{
    /// <summary>
    /// Extensibility Helper Class
    /// </summary>
    public static class ExtensibilityHelper
    {
        /// <summary>
        /// Gets the registered elements.
        /// </summary>
        /// <typeparam name="TInfo">The type of the info.</typeparam>
        /// <param name="provider">The provider.</param>
        /// <returns></returns>
        public static TInfo[] GetRegisteredElements<TInfo>(this  IServiceProvider provider)
        {
            IRegElementsService<TInfo> regService = provider.GetRegService<TInfo>();
            if (regService != null)
            {
                return regService.GetRegisteredElements();
            }
            return EmptyArray<TInfo>.Value;
        }

        /// <summary>
        /// Gets the reg service.
        /// </summary>
        /// <typeparam name="TInfo">The type of the info.</typeparam>
        /// <param name="provider">The provider.</param>
        /// <returns></returns>
        [CanBeNull]
        public static IRegElementsService<TInfo> GetRegService<TInfo>(this IServiceProvider provider)
        {
            return provider.GetService<IRegElementsService<TInfo>>();
        }
    }
}
